package com.carrental.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.carrental.entity.CarList;
import com.carrental.service.CarListService;

/**
 * Servlet implementation class CarListUpdateServlet
 */
@WebServlet("/CarListUpdateServlet")
public class CarListUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	CarListService carListService;   
	
    /**
     * @throws Exception 
     * @see HttpServlet#HttpServlet()
     */
    public CarListUpdateServlet() throws Exception {
        super();
        carListService = new CarListService();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		String model = request.getParameter("model");
		String number = request.getParameter("number");
		String price = request.getParameter("price");
		
		CarList carList = new CarList();
		carList.setId(id);
		carList.setModel(model);
		carList.setNumber(Integer.parseInt(number));
		carList.setPrice(Double.valueOf(price));
		
		System.out.println("修改汽车：" + carList);
		
		try {
			carListService.update(carList);
			response.sendRedirect("admin.jsp");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
